package com.smart.workflow.subscribers;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.smart.workflow.markers.EventSubscriber;
import com.smart.workflow.models.SMSInputEvent;
import com.smart.workflow.runners.SMSRunner;

/**
 * This is a class that gets information about all sms events. It should be a
 * singleton - this however doesn't cause any performance problems, as the class
 * only responsibility is only to add event to queue
 * 
 * @author Lukasz
 * 
 */
public class SMSSubscriber implements EventSubscriber {
	
	/**
	 * Number of threads that will be working with sms events
	 */
	private int threadWorkers;
	private ExecutorService smsThreadPool;

	public SMSSubscriber() {
		//default
		this.threadWorkers = 5;
		smsThreadPool = Executors.newFixedThreadPool(threadWorkers);
	}
	
	public SMSSubscriber(int numberOfWorkingThreads) {
		super();
		this.threadWorkers = numberOfWorkingThreads;
		smsThreadPool = Executors.newFixedThreadPool(threadWorkers);
	}

	@Override
	public void update(Object event) {
		smsThreadPool.submit(new SMSRunner(event));
	}
	
	@Override
	public Class<SMSInputEvent> getEventType() {
		return SMSInputEvent.class;
	}

	public void setThreadWorkers(int threadWorkers) {
		this.threadWorkers = threadWorkers;
	}

	public int getThreadWorkers() {
		return threadWorkers;
	}

}
